/***********************
 * Source Activity Panel
 */
AIR2.Source.Activity = function() {
    var setSubject = function(values) {
        if(values.ActivityMaster.actm_type == 'I')
            return AIR2.Format.sourceName(values.Source, true);
        else if(values.ActivityMaster.actm_type == 'S')
            return 'Status change: ';
        else if(values.ActivityMaster.actm_type == 'C')
            return "An analyst ";
        else
            return "Other: ";
    };
    return new AIR2.UI.Panel({
        colspan: 2,
        title: 'Activity',
        iconCls: 'air2-source-activities-icon',
        storeData: AIR2.Source.ACTIVDATA,
        url: AIR2.Source.BASEURL + '/activities',
        itemSelector: '.air2-source-activities',
        tpl: new Ext.XTemplate(
            '<table><tpl for=".">' +
              '<tr class="air2-source-activities">' +
                '<td>' +
                  '<span class="{[AIR2.Source.setActivityIcon(values)]}">' +
                    '{[this.setSubject(values)]}' +
                    ' <b>{[values.ActivityMaster.actm_name]}</b>' +
                    ': {sact_desc}' +
                  '</span>' +
                '</td>' +
                '<td class="date">{[AIR2.Format.date(values.sact_dtim)]}</td>' +
              '</tr>' +
            '</tpl></table>',
            {
                compiled: true,
                disableFormats: true,
                setSubject: setSubject
            }
        ),
        editModal: {
            allowAdd: false,
            width: 1000,
            items: {
                xtype: 'air2liveeditor',
                url: AIR2.Source.BASEURL + '/activities',
                sortField: 'sact_cre_dtim',
                sortDir: 'DESC',
                pageSize: 30,
                allowEdit: false,
                allowDelete: false,
                tpl: new Ext.XTemplate(
                    '<table width="100%">' +
                      '<tr class="air2-source-activities">' +
                        '<td>' +
                          '<span class="{[AIR2.Source.setActivityIcon(values)]}">' +
                            '{[this.setSubject(values)]}' +
                            ' <b>{[values.ActivityMaster.actm_name]}</b>' +
                            ': {sact_desc}' +
                          '</span>' +
                        '</td>' +
                        '<td class="date-long">{[AIR2.Format.dateLong(values.sact_dtim)]}</td>' +
                      '</tr>' +
                    '</table>',
                    {
                        compiled: true,
                        disableFormats: true,
                        setSubject: setSubject
                    }
                )                
            }
        }        
    });
}
